-- SPDX-License-Identifier: GPL-3.0-or-later

--- 交换两个角色的同区域手牌
--- 这玩意可以考虑参考心变在标林做鲁大师用的函数
---@param player ServerPlayer
---@param player2 ServerPlayer
---@param card_position integer
VslUtil.exchange_cards = function(player, player2, card_position)
    if player:isAlive() and player2:isAlive() then
      local room = player.room
      local ids = player:getCardIds(card_position)
      local ids2 = player2:getCardIds(card_position)
      local car_pos_ano = VslUtil.cpos_change(card_position)
      -- local fakemove = {
      --   toArea = car_pos_ano,
      --   to = player2.id,
      --   moveInfo = table.map(ids, function(id) return {cardId = id, fromArea = car_pos_ano} end),
      --   moveReason = fk.ReasonJustMove,
      -- }
      -- room:notifyMoveCards({player2}, {fakemove})
      -- local fakemove2 = {
      --     toArea = car_pos_ano,
      --     to = player.id,
      --     moveInfo = table.map(ids2, function(id) return {cardId = id, fromArea = car_pos_ano} end),
      --     moveReason = fk.ReasonJustMove,
      -- }
      -- room:notifyMoveCards({player}, {fakemove2})
      if #ids > 0 then
        room:moveCards({
          ids = ids,
          -- fromArea = car_pos_ano,
          to = player2.id,
          toArea = car_pos_ano,
          moveReason = fk.ReasonExchange,
          moveVisible = false
        })
      end
      if #ids2 > 0 then
        room:moveCards({
          ids = ids2,
          -- fromArea = car_pos_ano,
          to = player.id,
          toArea = car_pos_ano,
          moveReason = fk.ReasonExchange,
          moveVisible = false
        })
      end
    end
  end